package com.appbee.article.client;

import javax.inject.Inject;

import com.appbee.article.client.presenter.ArticleActivity;
import com.appbee.article.client.ui.ArticleSettingsView;
import com.appbee.core.client.modular.IModulRegistry;
import com.appbee.core.client.modular.SettingsView;
import com.appbee.core.client.modular.impl.ActivityModul;
import com.google.gwt.inject.client.AsyncProvider;
import com.google.gwt.user.client.rpc.AsyncCallback;

public class ArticleActivityModul extends ActivityModul
{
	private static final String ARTICLE = "article";
	private final IModulRegistry registry;
	private final AsyncProvider<ArticleSettingsView> settingsViewProvider;

	@Inject
	public ArticleActivityModul(IModulRegistry registry,
								AsyncProvider<ArticleActivity> articleActivityProvider,
								AsyncProvider<ArticleSettingsView> settingsViewProvider)
	{
		this.registry = registry;
		this.settingsViewProvider = settingsViewProvider;
		setDefaultActivty(articleActivityProvider);
	}

	public void register()
	{
		registry.register(ARTICLE, this);
	}

	@Override
	public String getName()
	{
		return "Article";
	}

	@Override
	public String getId()
	{
		return ARTICLE;
	}

	@Override
	public void getSettingsView(final AsyncCallback<SettingsView> callback)
	{
		settingsViewProvider.get(new AsyncCallback<ArticleSettingsView>()
		{

			@Override
			public void onSuccess(ArticleSettingsView result)
			{
				callback.onSuccess(result);
			}

			@Override
			public void onFailure(Throwable caught)
			{
				callback.onFailure(caught);
			}
		});
	}

}
